From e7dcf6675f062636b41da5edbd438d58712edf0d Mon Sep 17 00:00:00 2001 From: robertl Date: Sun, 6 Mar 2011 22:59:44 +0000 Subject: [PATCH] Overhaul new Explorist code to work with the released firmware. UNIX only for now. That'll teach me to trust pre-releases. Grrr. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4052 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/config.h.in | 3 ++ gpsbabel/configure.in | 2 +- gpsbabel/explorist_ini.c | 59 +++++++++++++++++++++++---------- gpsbabel/explorist_ini.h | 2 +- gpsbabel/magproto.c | 71 ++++++++++++++++++++++++++++++++++++---- 5 files changed, 110 insertions(+), 27 deletions(-) diff --git a/gpsbabel/config.h.in b/gpsbabel/config.h.in index 393348a85..c80201995 100644 --- a/gpsbabel/config.h.in +++ b/gpsbabel/config.h.in @@ -30,6 +30,9 @@ /* Define to 1 if you have the `sleep' function. */ #undef HAVE_SLEEP +/* Define to 1 if you have the `glob' function. */ +#undef HAVE_GLOB + /* Define to 1 if you have the `uname' function. */ #undef HAVE_UNAME diff --git a/gpsbabel/configure.in b/gpsbabel/configure.in index 102f4de18..b10eb7c89 100644 --- a/gpsbabel/configure.in +++ b/gpsbabel/configure.in @@ -372,7 +372,7 @@ AC_SUBST(DOCDIR) # AC_FUNC_STRTOD # AC_FUNC_VPRINTF # AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul]) -AC_CHECK_FUNCS([nanosleep sleep uname]) +AC_CHECK_FUNCS([nanosleep sleep uname glob]) # # Checks for how the system handles va_list diff --git a/gpsbabel/explorist_ini.c b/gpsbabel/explorist_ini.c index cc6136e54..accf8d706 100644 --- a/gpsbabel/explorist_ini.c +++ b/gpsbabel/explorist_ini.c @@ -10,32 +10,55 @@ explorist_read_value(const char* section, const char *key) { return inifile_readstr(inifile, section, key); } -mag_info * -explorist_ini_get() { - mag_info *info = xmalloc(sizeof(mag_info)); +static mag_info * +explorist_ini_try(const char *path) { + mag_info *info = NULL; + char *inipath; char *s; - inifile = inifile_init("Geocaches.ini", myname); - s = xstrdup(inifile_readstr(inifile, "Geocaches", "GeocachesPath")); - s = gstrsub(s, "\\", "/"); - info->geo_path = s; - inifile_done(inifile); + xasprintf(&inipath, "%s/%s", path, "APP/Atlas.ini"); + inifile = inifile_init(inipath, myname); + if (!inifile) { + xfree (inipath); + return NULL; + } - inifile = inifile_init("Tracks.ini", myname); - s = xstrdup(inifile_readstr(inifile, "Tracks", "TracksExportPath")); - s = gstrsub(s, "\\", "/"); - info->track_path = xstrappend(s, "/tracks.gpx");; - inifile_done(inifile); + info = xmalloc(sizeof(mag_info)); + info->geo_path = NULL; + info->track_path = NULL; + info->waypoint_path = NULL; - inifile = inifile_init("Waypoints.ini", myname); - s = xstrdup(inifile_readstr(inifile, "Waypoints", "WaypointsPath")); - s = gstrsub(s, "\\", "/"); - info->waypoint_path = xstrappend(s, "/newwaypoints.gpx"); - inifile_done(inifile); + s = xstrdup(inifile_readstr(inifile, "UGDS", "WpFolder")); + if (s) { + s = gstrsub(s, "\\", "/"); + xasprintf(&info->waypoint_path, "%s/%s", path, s); + } + s = xstrdup(inifile_readstr(inifile, "UGDS", "GcFolder")); + if (s) { + s = gstrsub(s, "\\", "/"); + xasprintf(&info->geo_path, "%s/%s", path, s); + } + s = xstrdup(inifile_readstr(inifile, "UGDS", "TrkFolder")); + if (s) { + s = gstrsub(s, "\\", "/"); + xasprintf(&info->track_path, "%s/%s", path, s); + } + inifile_done(inifile); + xfree (inipath); return info; } +mag_info * +explorist_ini_get(const char **dirlist) { + mag_info *r = NULL; + while (dirlist && *dirlist) { + r = explorist_ini_try(*dirlist); + if (r) return r; + } + return r; +} + void explorist_ini_done(mag_info *info) { xfree(info->geo_path); diff --git a/gpsbabel/explorist_ini.h b/gpsbabel/explorist_ini.h index fce970806..665b0de37 100644 --- a/gpsbabel/explorist_ini.h +++ b/gpsbabel/explorist_ini.h @@ -8,5 +8,5 @@ typedef struct { char* waypoint_path; } mag_info; -mag_info * explorist_ini_get(); +mag_info * explorist_ini_get(const char **directory_list); void explorist_ini_done(mag_info *info); diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index 5d89110de..5220efcec 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -28,6 +28,10 @@ #include "gbser.h" #include "explorist_ini.h" +#if HAVE_GLOB +#include +#endif + static int bitrate = 4800; static int wptcmtcnt; static int wptcmtcnt_max; @@ -58,6 +62,7 @@ static int extension_hint; // (This has nothing to do with the Explorist 100...600 products.) static ff_vecs_t *gpx_vec; static mag_info *explorist_info; +static char ** os_gpx_files(const char *dirname); /* * Magellan's firmware is *horribly* slow to send the next packet after @@ -108,6 +113,7 @@ static int ignore_unable; static waypoint * mag_wptparse(char *); typedef char * (cleanse_fn) (char *); static cleanse_fn *mag_cleanse; +static const char ** os_get_magellan_mountpoints(); static icon_mapping_t gps315_icon_table[] = { { "a", "filled circle" }, @@ -751,9 +757,12 @@ mag_rd_init_common(const char *portname) // We actually do the rd_init() inside read as we may have multiple // files that we have to read. if (0 == strcmp(portname, "usb:")) { - char *vec_opts = NULL; - explorist_info = explorist_ini_get(); - gpx_vec = find_vec("gpx", &vec_opts); + const char **dlist = os_get_magellan_mountpoints(); + explorist_info = explorist_ini_get(dlist); + if (explorist_info) { + char *vec_opts = NULL; + gpx_vec = find_vec("gpx", &vec_opts); + } return; } @@ -1211,17 +1220,36 @@ static void mag_read(void) { if (gpx_vec) { - gpx_vec->rd_init(explorist_info->track_path); - gpx_vec->read(); + char **f = os_gpx_files(explorist_info->track_path); + while (f && *f) { + gpx_vec->rd_init(*f); + gpx_vec->read(); + f++; + } + + f = os_gpx_files(explorist_info->waypoint_path); + while (f && *f) { + gpx_vec->rd_init(*f); + gpx_vec->read(); + f++; + } +#if 0 + f = os_gpx_files(explorist_info->geo_path); + while (f && *f) { + gpx_vec->rd_init(*f); + gpx_vec->read(); + f++; + } +#endif return; } found_done = 0; if (global_opts.masked_objective & TRKDATAMASK) { magrxstate = mrs_handoff; - if (!is_file) + if (!is_file) mag_writemsg("PMGNCMD,TRACK,2"); - + while (!found_done) { mag_readmsg(trkdata); } @@ -1530,6 +1558,35 @@ mag_write(void) } } +const char ** os_get_magellan_mountpoints() +{ +#if __APPLE__ + const char **dlist = xcalloc(2, sizeof *dlist); + dlist[0] = xstrdup("/Volumes/Magellan"); + dlist[1] = NULL; + return dlist; +#else + fatal("Not implemented"); +#endif +} + +// My kingdom for container classes and portable tree-walking... +// Returns a pointer to a static vector that's valid until the next call. +static char ** +os_gpx_files(const char *dirname) +{ +#if HAVE_GLOB + static glob_t g; + char *path; + xasprintf(&path, "%s/*.gpx", dirname); + glob(path, 0, NULL, &g); + xfree(path); + return g.gl_pathv; +#else + fatal("Not implemented"); +#endif +} + /* * This is repeated just so it shows up as separate menu options * for the benefit of GUI wrappers. -- 2.30.2